#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

#include "tsp_measurement.h"
#include "tcs_struct.h"
#include "system_information.h"   
#include <string.h>

using namespace std;
/** 
 * @brief 本程序用于对TSP的获取硬件信息接口进行测试
 */
void TSP_test_hardware(){
	
	cMeasurement	cMtest;
	CPUINFO	cpuInfo;
	UINT32			rst;
		
	/*空指针测试*/
	rst = cMtest.getHardwareInfo(NULL);
	printf("TSP: getHardwareInfo test_null_pointer result id = %x\n", rst);
		
	/*TCP连接失败测试*/
	rst = cMtest.getHardwareInfo("126.1.1.1",&cpuInfo);
	printf("TSP: getHardwareInfo test_TCP result id = %x\n", rst);
	
	/*本地正常结果*/
	rst = cMtest.getHardwareInfo(&cpuInfo);
	printf("TSP: getHardwareInfo test_local result id = %x\n", rst);
	printf("TSP: CPU Company is %s\n", cpuInfo.Company);
	
	/*远程正常结果*/
	printf ("remote test:\n");
	rst = cMtest.getHardwareInfo("196.5.1.3",&cpuInfo);
	printf("TSP: getHardwareInfo test_remote result id = %x\n", rst);
	printf("TSP: CPU Company is %s\n", cpuInfo.Company);
	
}
/** 
 * @brief 本程序用于对TSP的获取软件信息接口进行测试
 */
void TSP_test_software(){

	cMeasurement	cMtest;
	SOFTINFO		softInfo;
	UINT32			rst;
	
	
	/*空指针测试*/
	rst = cMtest.getSoftwareInfo(NULL);
	printf("TSP: getSoftwareInfo test_null_pointer result id = %x\n", rst);
	
	/*TCP连接失败测试*/	
	rst = cMtest.getSoftwareInfo("126.1.1.1",&softInfo);
	printf("TSP: getSoftwareInfo test_TCP result id = %x\n", rst);
	
	/*本地正常结果*/
	rst = cMtest.getSoftwareInfo(&softInfo);
	printf("TSP: getSoftwareInfo test_local result id = %x\n", rst);
	printf("TSP: CPU Company is %s\n", softInfo.softname);
	
	/*远程测试*/	
	rst = cMtest.getSoftwareInfo("127.0.0.1",&softInfo);
	printf("TSP: getSoftwareInfo test_remote result id = %x\n", rst);
	printf("TSP: Software name is %s\n", softInfo.softname);	
	
}

/** 
 * @brief 本程序用于对程序文本进行动态度量
 */
void TSP_test_program(){
	cMeasurement	cMtest;
	BYTE*		pProgram;
	UINT32		rst;
	UINT32		length;

	length = 40;
	pProgram = (BYTE*)malloc(length);
	if(pProgram == NULL){
		printf("test malloc error\n");
		return;
	}
	/*测试文本赋值*/
	strcpy((char*)pProgram, "test for program");
	
	/*空指针测试*/
	rst = cMtest.programVerify(length, NULL);
	printf("TSP: programVerify test_null_pointer result is : %d\n", rst);
	
	/*TCP连接失败测试*/	
	rst = cMtest.programVerify(length, pProgram,"126.1.1.1");
	printf("TSP: programVerify test_TCP result is : %d\n", rst);
	
	/*本地正常结果*/
	rst = cMtest.programVerify(length, pProgram);
	printf("TSP: programVerify test_local result is : %d\n", rst);
	
	/*远程正常结果*/
	rst = cMtest.programVerify(length, pProgram,"127.0.0.1");
	printf("TSP: programVerify test_local remote is : %d\n", rst);
	
	free(pProgram);

}

/** 
 * @brief 本程序用于对平台的软硬件合法性进行度量
 */
void TSP_test_platform(){
	
	cMeasurement cMtest;
	
	PCPUINFO pCpu;
	PSOFTINFO pSoft;
	TSS_RESULT rst;
	
	/*硬件信息初始化*/
	pCpu = (PCPUINFO)malloc(sizeof(CPUINFO));
	if(pCpu == NULL)
		return;
	strcpy(pCpu->Company, "Cmy");
	strcpy(pCpu->BaseParam, "Jzd");
	strcpy(pCpu->SerialNumber, "5670");
	strcpy(pCpu->sha1_hash, "sha_1");

	/*软件信息初始化*/
	pSoft = (PSOFTINFO)malloc(sizeof(SOFTINFO));
	if(pSoft == NULL)
		return;
	strcpy(pSoft->softname, "xd");
	strcpy(pSoft->version, "v27");
	strcpy(pSoft->sha1_hash, "jiao");

	/*空指针测试*/
	rst = cMtest.platformVerify(NULL, NULL);
	printf("TSP: platformVerify test_null_pointer result id is : %d\n", rst);
	
	/*TCP连接失败测试*/
	rst = cMtest.platformVerify(pCpu, pSoft, "126.0.0.1");
	printf("TSP: platformVerify test_TCP result id is : %d\n", rst);
	
	/*本地正常结果*/
	rst = cMtest.platformVerify(pCpu, pSoft);
	printf("TSP: platformVerify test_local result id is : %d\n", rst);
	
	/*远程正常结果*/
	rst = cMtest.platformVerify(pCpu, pSoft, "127.0.0.1");
	printf("TSP: platformVerify test_remote result id is : %d\n", rst);
	
	free(pCpu);
	free(pSoft);
}